package br.com.werp.regras.acesso.integracao;

import br.com.werp.regras.geral.Debuger;
import br.com.werp.regras.geral.ErroPadrao;
import br.com.werp.regras.geral.integracao.MasterDAO;
import br.com.werp.regras.geral.vos.acesso.RoleUrlVO;
import br.com.werp.regras.geral.vos.tabelas.Role_url;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import java.util.List;

import javax.servlet.jsp.tagext.TryCatchFinally;


public class RoleUrlDAO extends MasterDAO {
    private static RoleUrlDAO roleUrlDAO;
    public static final String REMOVER_ROLE_URL = "REMOVER_ROLE_URL";

    private RoleUrlDAO(String banco) throws Exception {
        super(banco);
    }

    public static RoleUrlDAO getRoleUrlDAO() throws Exception {
        if (roleUrlDAO == null) {
            roleUrlDAO = new RoleUrlDAO("");
        }

        return roleUrlDAO;
    }

    public List pesquisarRoleUrl(RoleUrlVO roleUrlVO) throws Exception {
        Connection connection = getConexao();

        try {
            String tabelas = "url,role_url";
            String where = " and rour_url = url_id";

            return pesquisarVO(connection, roleUrlVO, where, tabelas,
                RoleUrlVO.EXCLUIDAS);
        } finally {
            liberaConeccao(connection);
        }
    }

    public void apagarRole_url(Object key, Role_url role_url)
        throws Exception {
        Connection connection = validarTransacao(key);
        String query = getQuery(REMOVER_ROLE_URL);
        PreparedStatement statement = connection.prepareStatement(query);
        setInt(1, statement, role_url.getRour_id());
        Debuger.debugar(statement, getClass());
        statement.executeUpdate();
    }

    public void inserirRoleUrle(Object key, Role_url role_url)
        throws Exception {
        Connection connection = validarTransacao(key);
        inserirVO(connection, role_url, new String[] { "rour_id" });
    }
}
